/*
 * @Author: chichiksky
 * @Date: 2022-03-29 22:42:49
 * @LastEditTime: 2022-03-30 10:25:16
 * @LastEditors: your name
 * @Description: 
 * @FilePath: \web\src\assets\common\date.js
 */

const _date = {
  /**
   * 将标准格式转化为YY-MM-DD格式
   * @method changeTimeFormat
   * @param {String} str 标准时间
   * @param {Boolean} state true 包括年月日, false 包括时分秒
   * @return  格式化时间
   */
  changeTimeFormat: function (str, state=true) {
    const dateTime = new Date(str)
    const year = dateTime.getFullYear();
    const month = dateTime.getMonth() + 1;
    const date = dateTime.getDate();
    const hour = dateTime.getHours();
    const minute = dateTime.getMinutes();
    const second = dateTime.getSeconds();
    return state?`${year}-${this.addZero(month)}-${this.addZero(date)}`:`${year}-${this.addZero(month)}-${this.addZero(date)}  ${this.addZero(hour)}：${this.addZero(minute)}：${this.addZero(second)}`
  },
  /**
   * 不足10,则前方补0
   * @param {Number} v  
   * @returns {String}
   */
  addZero: function (v) {
    return v < 10 ? '0' + v : v
  }
}

export default _date;